﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using SharedGenomics.Core;
using SharedGenomics.Workbench.Messages;
using SharedGenomics.Workbench.Services;

namespace SharedGenomics.Workbench.Core
{
    public class CommandFactory
    {
        public CommandFactory(IEventBroker eventBroker)
        {
            this.EventBroker = eventBroker;
        }

        public ICommand CreateCommand(Action a)
        {
            return new Command(a);
        }

        public ICommand CreateOpenTaskCommand(ITask taskToOpen)
        {
            OpenTaskMessage message = new OpenTaskMessage(taskToOpen);
            return new Command(() => this.EventBroker.Publish(message));
        }

        public ICommand CreateOpenUriAnnotationCommand(Uri target, object args)
        {
            target.ThrowIfNull("target");
            NavigateUriMessage navigateMessage = new NavigateUriMessage(target);
            return new Command(() => this.EventBroker.Publish(navigateMessage));
        }

        public ICommand CreateOpenPresenterAnnotationCommand<T>(FormDisplayMode displayMode, Action<T> initialisationAction, object args) where T : IPresenter
        {
            ShowPresenterMessage message = new ShowPresenterMessage(displayMode, typeof(T), initialisationAction, null);
            return new Command(() => this.EventBroker.Publish(message));
        }

        private IEventBroker EventBroker { get; set; }
    }
}
